package com.edu.study.base.activationCode.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.edu.study.base.activationCode.domain.TbActivationCodeRy;
import com.edu.study.base.activationCode.service.ITbActivationCodeRyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 激活码Controller
 * 
 * @author jjt
 * @date 2021-03-01
 */
@RestController
@RequestMapping("/activation/activationCode")
public class TbActivationCodeRyController extends BaseController
{
    @Autowired
    private ITbActivationCodeRyService tbActivationCodeRyService;

    /**
     * 查询激活码列表
     */
    @PreAuthorize("@ss.hasPermi('activation:activationCode:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbActivationCodeRy tbActivationCodeRy)
    {
        startPage();
        List<TbActivationCodeRy> list = tbActivationCodeRyService.selectTbActivationCodeRyList(tbActivationCodeRy);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('activation:activationCode:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(TbActivationCodeRy tbActivationCodeRy)
    {
        startPage();
        List<TbActivationCodeRy> list = tbActivationCodeRyService.selectTbActivationCodeRyListWithOther(tbActivationCodeRy);
        return getDataTable(list);
    }
    /**
     * 导出激活码列表
     */
    @PreAuthorize("@ss.hasPermi('activation:activationCode:export')")
    @Log(title = "激活码", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbActivationCodeRy tbActivationCodeRy)
    {
        List<TbActivationCodeRy> list = tbActivationCodeRyService.selectTbActivationCodeRyListWithOther(tbActivationCodeRy);
        ExcelUtil<TbActivationCodeRy> util = new ExcelUtil<TbActivationCodeRy>(TbActivationCodeRy.class);
        return util.exportExcel(list, "activationCode");
    }

    /**
     * 获取激活码详细信息
     */
    @PreAuthorize("@ss.hasPermi('activation:activationCode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(tbActivationCodeRyService.selectTbActivationCodeRyById(id));
    }

    /**
     * 新增激活码
     */
    @PreAuthorize("@ss.hasPermi('activation:activationCode:add')")
    @Log(title = "激活码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbActivationCodeRy tbActivationCodeRy)
    {
        return toAjax(tbActivationCodeRyService.insertTbActivationCodeRy(tbActivationCodeRy));
    }

    @PreAuthorize("@ss.hasPermi('activation:activationCode:add')")
    @Log(title = "激活码", businessType = BusinessType.INSERT)
    @PostMapping("saveActivationCode")
    public AjaxResult save(@RequestBody TbActivationCodeRy tbActivationCodeRy)
    {
        return AjaxResult.success(tbActivationCodeRyService.batchInsert(tbActivationCodeRy));
    }
    /**
     * 修改激活码
     */
    @PreAuthorize("@ss.hasPermi('activation:activationCode:edit')")
    @Log(title = "激活码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbActivationCodeRy tbActivationCodeRy)
    {
        return toAjax(tbActivationCodeRyService.updateTbActivationCodeRy(tbActivationCodeRy));
    }

    /**
     * 删除激活码
     */
    @PreAuthorize("@ss.hasPermi('activation:activationCode:remove')")
    @Log(title = "激活码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbActivationCodeRyService.deleteTbActivationCodeRyByIds(ids));
    }
}
